package member.base.action;

import m.common.action.ActionRequest;
import m.common.action.Param;
import m.common.action.RequestMethod;
import m.common.model.util.*;
import m.system.cache.CacheUtil;
import m.system.util.JSONMessage;
import member.base.model.StoreInfo;
import member.base.model.UserInfo;
import member.base.util.PowerUtil;

@ActionRequest(name = "action/base/storeInfo",description = "店铺信息")
public class StoreInfoAction extends BaseAction{

    @RequestMethod(description = "列表")
    public JSONMessage getList() throws Exception {
        ModelQueryList queryList=toQueryList(StoreInfo.class,"*","user.realName","user.phoneNum");
        queryList.addCondition(QueryCondition.eq("business.oid", PowerUtil.getBusiness().getOid()));
        return JSONMessage.success("查询成功").push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @RequestMethod(description = "保存")
    public JSONMessage save(@Param("model") StoreInfo model) throws Exception {
        PowerUtil.verifyPower(UserInfo.PowerManage);
        model.setBusiness(PowerUtil.verifyBusiness(model.getBusiness()));
        ModelQueryCheck.init(model)
            .checkNotNull("color","颜色不能为空")
            .checkNotNull("name","店铺名称不能为空")
            .doCheck(false,true);
        ModelCheckUtil.checkUniqueCombine(model,new String[]{"business.oid","name"},"店铺名称已存在");
        ModelUpdateUtil.saveModel(model);
        PowerUtil.clearStore(model.getOid());
        return JSONMessage.success("保存成功");
    }
}
